package com.badibadi.mail;

import java.util.HashMap;
import java.util.Map;

import com.badibadi.activity.BaseActivity;
import com.badibadi.infos.PayUserContactShow1Model;
import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.id;
import com.badibadi.uniclubber.R.layout;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

//zaicihuiying //tuikuan
public class Mail_32_33bumanyiyuanyingActivity extends BaseActivity {//zaicihuiying

	String is_dafang;// 是否是答方0：不是 1：是
	PayUserContactShow1Model payUserContactShow1Model;

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(Mail_32_33bumanyiyuanyingActivity.this);
				try {
					Utils.showMessage(Mail_32_33bumanyiyuanyingActivity.this,
							getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 2://满意
				Utils.ExitPrgress(Mail_32_33bumanyiyuanyingActivity.this);
				try {
					Utils.showMessage(
							Mail_32_33bumanyiyuanyingActivity.this,
							getResources().getString(
									R.string.wx_tuikuan_success));
					Intent intent = new Intent(
							Mail_32_33bumanyiyuanyingActivity.this,
							Mail34_36Activity.class);
					intent.putExtra("payUserContactShow1Model",
							payUserContactShow1Model);
					startActivity(intent);
					finish();
				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			case 3:
				Utils.ExitPrgress(Mail_32_33bumanyiyuanyingActivity.this);
				try {
					Utils.showMessage(Mail_32_33bumanyiyuanyingActivity.this,
							getResources().getString(R.string.l_xb12));
				} catch (Exception e) {
					// TODO: handle exception
					// throw new NullPointerException("getActivity() is Null");
				}
				break;
			case 4:
				Utils.ExitPrgress(Mail_32_33bumanyiyuanyingActivity.this);
				try {
					Utils.showMessage(Mail_32_33bumanyiyuanyingActivity.this,
							getResources().getString(R.string.wx_tuikuai_false));

				} catch (Exception e) {
					// TODO: handle exception
				}

				break;
			default:
				break;
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.activity_mail_32_33bumanyiyuanying);

		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		payUserContactShow1Model = (PayUserContactShow1Model) getIntent()
				.getSerializableExtra("payUserContactShow1Model");
		is_dafang = getIntent().getStringExtra("flags");

		// 不满意原因
		TextView contents = (TextView) this.findViewById(R.id.contents);
		contents.setText(""
				+ payUserContactShow1Model.getZhannei_usercontact().get(0)
						.getDissatisfied_reason());

		if (is_dafang.equals("1"))// 答方
		{
			TextView title_mail = (TextView) this.findViewById(R.id.title_mail);
			title_mail.setText(getResources().getString(
					R.string.Not_satisfied_with_reason));
			// LinearLayout
			// ll_bottom=(LinearLayout)this.findViewById(R.id.ll_bottom);
			// ll_bottom.
			// 再次回应
			Button zaicihuiying = (Button) this.findViewById(R.id.zaicihuiying);
			zaicihuiying.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(
							Mail_32_33bumanyiyuanyingActivity.this,
							Mail15_huifuActivity.class);
					intent.putExtra("payUserContactShow1Model",
							payUserContactShow1Model);

					startActivity(intent);
					finish();
				}
			});
			// 退款
			Button tuikuan = (Button) this.findViewById(R.id.tuikuan);
			tuikuan.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					com.badibadi.mytools.Dialog d = new com.badibadi.mytools.Dialog();
					d.CreateDialog(Mail_32_33bumanyiyuanyingActivity.this,
							getResources().getString(R.string.wx_is_tuikuan),
							getResources().getString(R.string.wx_txt_79));
					d.setOnDialogClistener(new com.badibadi.mytools.Dialog.DialogClistener() {

						@Override
						public void ret() {
							// TODO Auto-generated method stub

						}

						@Override
						public void ok() {
							// TODO Auto-generated method stub
							refund();
						}
					});

				}
			});

		} else// 问方
		{
			TextView title_mail = (TextView) this.findViewById(R.id.title_mail);
			title_mail.setText(getResources().getString(
					R.string.wx_reply_zhanneixin));
			TextView tishi = (TextView) this.findViewById(R.id.tishi);
			tishi.setText(getResources().getString(R.string.bumanyi_));
			tishi.setVisibility(View.VISIBLE);
			LinearLayout ll_bottom = (LinearLayout) this
					.findViewById(R.id.ll_bottom);
			ll_bottom.setVisibility(View.GONE);
		}
	}

	// 退款
	public void refund() {
		Utils.showPrgress(Mail_32_33bumanyiyuanyingActivity.this);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("zhaneniId", payUserContactShow1Model.getZhannei_Id());
		map.put("uid", Utils.getUid(Mail_32_33bumanyiyuanyingActivity.this));
		map.put("reply_id", payUserContactShow1Model.getZhannei_usercontact()
				.get(0).getThisMsgId());
		CommonUtils.CommomPostfunction(Mail_32_33bumanyiyuanyingActivity.this,
				Constants.BadiUrl_1 + "/" + "inform/refund", map, handler, 1,
				3, 2, 4);
	}
	// // 不满意操作
	// public void displeased() {
	// Intent intent=new
	// Intent(Mail21_22_18Activity.this,MailbumanyiActivity.class);
	// intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
	// startActivity(intent);
	// finish();
	// }

}
